<template>
    <h3>添加借款信息</h3>
    借款名称：<input type="text" v-model="Jname1" />
    利息：<select v-model="IId">
        <option value="0">请选择</option>
        <option v-for="item in str" :key="item.IId" :value="item.IId">
            {{ item.IInverest }}</option>
    </select>
    <button @click="Show">查询</button>
    <table>
        <thead>
            <tr>
                <td>借款款项名称</td>
                <td>借款最高金额</td>
                <td>借款最高年限</td>
                <td>借款款项简介</td>
                <td>操作</td>
            </tr>
        </thead>
        <tbody>
            <tr v-for="it in arr" :key="it.JId" :value="it.JName">
                <td>{{ it.JName }}</td>
                <td>{{ it.MaxMoney }}</td>
                <td>{{ it.MaxYear }}</td>
                <td>{{ it.Info }}</td>
                <td><button @click="Del(it.JId)">删除</button>
                    <button @click="Upt(it.JId)">修改</button>
                </td>
            </tr>
        </tbody>
    </table>
</template>
<script setup lang="ts">
import { ref, onMounted } from "vue";
import axios from 'axios';
import { useRouter } from 'vue-router';

const IId = ref('0');
const Jname1 = ref('');
//绑定下拉
const str = ref([]);
onMounted(() => {
    axios.get('http://localhost:62489/api/Jie/BindInverest', {
        params: {
            IId: IId
        }
    })
        .then(res => {
            str.value = res.data;
            console.log(res.data);
        })
        .catch(error => {
            console.log(error);
        })
})
const arr = ref([
    {
        JId: 0,
        Jname: '',
        MaxMoney: 0,
        MaxYear: 0,
        Info: ''
    }
])
//显示+查询
onMounted(() => {
    Show();
})
const Show = () => {
    axios.get('http://localhost:62489/api/Jie/ShowJieKuan', {
        params: {
            name: Jname1.value,
            iId: IId.value
        }
    })
        .then(res => {
            arr.value = res.data;
            console.log(res.data);
        })
        .catch(error => {
            console.log(error);
        })
}
//删除
const Del = (JId: number) => {
    axios.get('http://localhost:62489/api/Jie/Delete', {
        params: {
            jid: JId
        }
    })
        .then(res => {
            if (res.data > 0) {
                alert("删除成功")
                Show();
            }
            else {
                alert("删除失败")
                return;
            }
        })
        .catch(error => {
            console.log(error);
        })
}
//修改
const router = useRouter();
const Upt = (JId: number) => {
    router.push(
        {
            name: 'Update',
            params: {
                JId: JId
            }
        }
    );
}
</script>